#ifndef USB_CAMERA_HPP
#define USB_CAMERA_HPP

#include <linux/videodev2.h>

#define DEVICE_NAME "/dev/video0"
#define WIDTH 640
#define HEIGHT 480
#define BUFFERS_NUMBERS 16

class USBCamera{

public:
    bool openCamera();
    bool closeCamera();
    int readFrameBuffer(void * buffer , unsigned int * size);
    void yuyvToJPEG(unsigned char* yuyv_data, int width, int height, int quality, const char* output_file);
    int yuyv422ToYUV420(unsigned char * input_buffer,int width, int height,unsigned char * output_buffer);
    int yuv420ToH264(unsigned char *input_buffer, unsigned int input_size, unsigned char *out_data, unsigned int *out_size);
    static USBCamera * getInstance();
private:
    int fd = -1;
    struct buffer{
        void * start;
        int length;
    };
    struct buffer buffers[BUFFERS_NUMBERS];
    struct v4l2_capability cap;
    struct v4l2_fmtdesc video_format_desc; 
    struct v4l2_format fmt;
    struct v4l2_buffer buf;
    struct v4l2_requestbuffers req_buffers;
};







#endif
